#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sqlalchemy

__auther__ = 'teffy'

'''
@filename command
@created on 2017-12-18
@poject:work-kit
@auther:teffy
'''

from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from settings import Settings


def create_table():
    global settings, engine, command
    settings = Settings()
    engine = create_engine('sqlite:///' + settings.db_file)
    metadata = MetaData(engine)
    command = Table('commands', metadata,
                    Column(Integer, primary_key=True, autoincrement=True),
                    Column(Integer),
                    Column(String(20)),
                    Column(String(200))
                    )
    metadata.create_all(engine)


create_table()

# engine = create_engine('sqlite:///' + settings.db_file)
# Base = declarative_base()
#
#
# class Command(Base):
#     __tablename__ = 'commands'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     parent_id = Column(Integer)
#     command = Column(String(20))
#     param = Column(String(200))
#
#     def __repr__(self):
#         return "<Command(id='%d',parent_id='%d',command='%s',param='%s'>" % (
#             self.id, self.parent_id, self.command, self.param)
#
#
# print(Command.__table__)
#
# DBSession = sessionmaker(bind=engine)
# session = DBSession()
# new_command = Command(parent_id=0, command='adba', param='devices')
# session.add(new_command)
# session.commit()
# session.close()
